import os
import time

import pandas as pd
from concurrent import futures
def submit_analysis():
    today=time.strftime("%Y-%m-%d", time.localtime())
    # today ="2023-05-18"
    current_dir = os.path.dirname(os.path.realpath(__file__))
    try:
        df = pd.read_csv(current_dir+'/data_csv/'+today+'筹码分布.csv', encoding='gbk')
    except Exception as e:
        return
        # df = pd.read_csv(current_dir+'/data_csv/2023-05-29筹码分布.csv', encoding='gbk')


    stocks=[]


    i = 1
    i688=1
    for row in df.itertuples():
        # print(row)

        # if row[2] contain '688' then continue
        if '688' in row[2]:
            # print(row[2])
            # print(i688)
            # i688+=1
            continue
        # break

        # 集中度
        ConcentrationRatio = row[8].replace('%', '')
        # 获利比例
        huoli = row[3].replace('%', '')
        specile_code = '301369'
        if specile_code in row[2] and 1==3:
            print("r6", ConcentrationRatio)
            print("huoli",huoli)
            print("cbj:",float(row[4]))
            print("max min:",float(row[9]) , float(row[10]))
            print("max min /2:",(float(row[9]) + float(row[10])) / 2)
            break

        # and 'CY' not in row[2]
        try:
            if float(ConcentrationRatio) < 20 and float(huoli) < 85 and float(huoli) > 5 and float(row[4]) < (
                    float(row[9]) + float(row[10])) / 2:
                # print(row)
                # 70%筹码 价格区间
                up_down = row[7].split("-")
                percent_list = (float(up_down[1]) - float(up_down[0])) / (float(row[9]) - float(row[10])) * 100


                #002518
                specile_code='002728'
                if specile_code in row[2] and 1 == 1:
                    print(specile_code+' percent_list', percent_list)
                    print('percent_list', up_down[1], up_down[0], row[9], row[10])
                    # break
                if percent_list < 15:
                    # print(row)
                    # print('percent_list', up_down[1], up_down[0], row[9], row[10])
                    # print('max min:',row[9],row[10])
                    # print('percent_list', percent_list)
                    # print(row)
                    #_5 90%筹码 价格区间
                    #_6 90%筹码 集中度
                    #_7 70%筹码 价格区间
                    #_8 70%筹码 集中度

                    # print(row[2])
                    i = i + 1
                    # print('stock index:', i)

                    stocks.append([row[2].split('.')[0], row[1]])
        except Exception as e:
            print(e)




    print(len(stocks))
    stock_list=[]
    for i in stocks:
        print(i[0])
        stock_list.append({"name":i[0],"code":i[1]})

    print(stock_list)
    #post to server
    import requests
    import json

    url = "http://www.lqqq.top/getListOfAStock"
    url2 = "http://127.0.0.1:8080/getListOfAStock"
    #post stock_list to server
    #write a try catch
    try:
        response = requests.request("POST", url, data=json.dumps(stock_list))
        response = requests.request("POST", url2, data=json.dumps(stock_list))
    except Exception as e:
        print(e)
        pass


        # if "002518" in row[2]:
        #     # print(row)
        #     # print(row[5])
        #     # print(row[7])
        #     print('percent_list',percent_list)
        #
        #     break
        # print()
